// ignore_for_file: library_private_types_in_public_api

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:jetour_line/my_colors.dart';
import 'package:jetour_line/utils/extension_int.dart';
typedef _SelectIndexCallBack = void Function(int index);
class TitleWidget extends StatefulWidget {
  final _SelectIndexCallBack selectIndexCallBack;
  final List<String> pageTitles;
  Color color;
  TitleWidget(this.pageTitles,{Key? key,required this.selectIndexCallBack,this.color = Colors.white}) : super(key: key);

  @override
  State<TitleWidget> createState() => _TitleWidgetState();
}

class _TitleWidgetState extends State<TitleWidget> {
  int selItem = 0;
  @override
  Widget build(BuildContext context) {
    int len = widget.pageTitles.length;
    return Container(
      child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
          for(int i = 0;i<len;i++)
            len >1? Expanded(child: itemWidget(i)):Container(width: 134.px, child: itemWidget(i)),
      ],),
    );
  }
  Widget itemWidget(int index){
    return GestureDetector(
      onTap: (){
        setState(() {
          selItem = index;
          if(widget.selectIndexCallBack != null){
            widget.selectIndexCallBack(index);
          }
        });
      },
      child: Container(
        width: double.infinity,
        height: double.infinity,
        color: widget.color,
        child: Stack(alignment: Alignment.center, children: [
          Text(widget.pageTitles[index],style: TextStyle(fontSize: 32.px,color:selItem == index? MyColors.color333333:MyColors.color999999 ,fontWeight:selItem == index?FontWeight.w600:FontWeight.w400 ),),
          Positioned(bottom: 0, child: Visibility(visible: selItem == index?true:false, child: Container(width: 40.px,height: 6.px,color: MyColors.color00A198,)))
        ],),
      ),
    );
  }
}
